//提示框工具类
function showLglTipsBox(width,height,title,content,btnCloseIsShow){
	$('.lgl-pop-background,.lgl-pop').remove();
    //../:不是主页
	let imgUrl = location.href.indexOf('userPages') > 0 ? '../' : '';
    $(document.body).css({"overflow-x": "hidden", "overflow-y": "hidden"});
    let btnStyle = 'padding:8px 15px;margin:15px 5px;border-radius: 5px;cursor:pointer;border:0;background: url(' + imgUrl + 'staticFile/images/index/menu-spacer.gif) repeat-x;color: #fff;',
        popStyle = 'position: fixed;left: 0;top: 0;';
    let html = '<div class="lgl-pop-background" style="' + popStyle + 'z-index: 129;width: 100%;height: 100%;background: rgba(0,0,0,.2);"></div>' +
        '<div class="lgl-pop" style="' + popStyle + 'width:' + width + 'px;height:' + height + 'px;min-height: 100px;bottom: 0;right: 0; margin: auto;padding: 25px;z-index: 130;border-radius: 8px;background-color: #fff;fonts-size: 16px;box-shadow: 0 3px 18px rgba(100, 0, 0, .5);">' +
        '<div style="height:40px;line-height:40px;width:100%;border-bottom: 1px #E5E5E5 solid;margin-top:-40px;"><h4>' + title + '</h4></div><div style="height: 38px;line-height: 38px;">' + content + '</div>' +
        '<div style="border-top: 1px #E5E5E5 solid;text-align: right;">' +
        (btnCloseIsShow ? '<input type="button" value="关闭" onclick="closeLglTipsBox()" style="' + btnStyle + '">' : '') +
        '<input id="btnLglTipsBoxOk" type="button" value="确定" onclick="closeLglTipsBox()" style="' + btnStyle + '"></div></div>';
    $(document.body).append(html);
}
/**
 * 隐藏提示框口
 * @returns
 */
function closeLglTipsBox(){
	$('.lgl-pop-background,.lgl-pop').hide();
    $(document.body).css({"overflow-x": "auto", "overflow-y": "auto"});
}
/**
 * 全局AJAX请求拦截器，请求成功完后会首先执行这段代码
 */
jQuery(function ($) {
    // 备份jquery的ajax方法
    let _ajax = $.ajax;
    // 重写ajax方法，先判断登录在执行success函数
    $.ajax = function (opt) {
        let _success = opt && opt.success || function (a, b) {};
        let _opt = $.extend(opt, {
            success: function (data, textStatus) {
                try {
                    //用户登录失效
                    if (data.status == -1) {
                        closeLglTipsBox();
                        alert('登录失效，请重新登录');
                        let thisUrl = location.href;
                        //如果是首页
                        if (thisUrl.indexOf('.html') < 1 || thisUrl.indexOf('orderDetail.html') > 1 ||
                            thisUrl.indexOf('issueVent.html') > 1) {
                            $('.loading').hide();
                            showLoginWindow();
                        } else {
                            sessionStorage.setItem('lastRequestUrl', window.location.href);//本次要请求的URL
                            window.location.href = '/userPages/userLogin.html';
                        }
                        $('#myUserName').remove();
                        $('#IamLogout').hide();
                        $('.user-register,.user-login').show();
                        delUserFromSession();
                        return;
                    }
                } catch (e) {
                }
                _success(data, textStatus);
            }
        });
        //继续执行原AJAX请求
        _ajax(_opt);
    };
});